package top.zhangjianyong.tools.service.mybatis.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import top.zhangjianyong.tools.entity.Guaguale;
import top.zhangjianyong.tools.mapper.GuagualeMapper;
import top.zhangjianyong.tools.service.mybatis.IGuagualeService;
import top.zhangjianyong.tools.utils.ApiResponse;

import java.util.List;

/**
 * @author ： zhangjianyong
 * @date ： 2023/3/13 9:18 AM
 */
@Service
public class IGuagualeServiceImpl extends ServiceImpl<GuagualeMapper, Guaguale> implements IGuagualeService {

    @Override
    public List<Guaguale> listLimit(int limit) {
        return lambdaQuery()
                .eq(Guaguale::getDelFlag, 0)
                .orderByDesc(Guaguale::getCreateTime)
                .last("limit " + limit)
                .list();
    }

    @Override
    public boolean del(Long id) {
        return lambdaUpdate().eq(Guaguale::getId, id)
                .set(Guaguale::getDelFlag, 1)
                .update();
    }

    @Override
    public Guaguale qryByTypeAndCode(String type, String code) {
        return lambdaQuery().eq(Guaguale::getType, type)
                .eq(Guaguale::getCode, code).one();
    }
}
